package com.nnxy.service.impl;

import com.nnxy.mapper.StuDegreeMapper;
import com.nnxy.pojo.StuCount;
import com.nnxy.pojo.StuDegree;
import com.nnxy.service.StuDegreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Title: StuDegreeServiceImpl
 * @Author: Jer.
 * @Date: 2025/4/22 20:39
 */
@Service
public class StuDegreeServiceImpl implements StuDegreeService {
    @Autowired
    private StuDegreeMapper stuDegreeMapper;

    @Override
    public List<StuDegree> getStuDegreeData() {
        List<Map> degreeDataList = stuDegreeMapper.countStudentDegreeData();

        return degreeDataList.stream().map(map -> new StuDegree(
                (String) map.get("deg"),
                ((Number) map.get("num")).intValue()
        )).collect(Collectors.toList());
    }

    @Override
    public StuCount getStuCountDate() {
        List<Map> studentDateList = stuDegreeMapper.countStudentData();


        List clazzList = studentDateList.stream().map(map -> {
            return map.get("cot");
        }).toList();

        List dataList = studentDateList.stream().map(map -> {
            return map.get("num");
        }).toList();
        return new StuCount(clazzList, dataList);
    }
}
